const common = require('../../utils/common')
const { confirmReturn } = require('../../services/order')

Page({
  data: {
    type: '',
    payload: {}
  },
  onLoad: function ({ type, payload }) {
    if (!payload) return
    this.setData({
      type,
      payload: JSON.parse(payload)
    })
  },
  onUnload: function () {
    // 页面销毁时执行
    wx.navigateTo({ url: `/pages/all-order-list/index` })
  },
  onConfirm: function () {
    const { afterId, orderId } = this.data.payload
    confirmReturn({ afterId, orderId }).then(() => {
      wx.navigateTo({ url: `/pages/all-order-list/index` })
    }).catch(err => {
      common.log(err)
    })
  }
})
